﻿/// <reference path="D:\Documents\Visual Studio 2013\Projects\WinnerCMS\WinnerCMS.WebUI\Scripts/knockout-3.3.0.debug.js" />

function GetVote($obj) {

    $.ajax({
        type: "get",
        url: "/api/Vote/ShowVote",
        data: {
            Id: $obj.data("id")
        },
        dataType: "json",
        success: function (data) {
            if (data == null) return;
            ko.applyBindings(data, $obj[0]);
        }
    });
}


function PostVote($obj) {
    var datas = {
        Id: $obj.data("id"),
        VoteChoices: []
    };
    $obj.find("input[name='Selected']").each(function () {
        if (this.checked) {
            datas.VoteChoices.push({ Id: this.value });
        }
    });

    $.ajax({
        type: "POST",
        url: "/api/Vote/Post",
        data: datas,
        beforeSend: function () {
        },
        success: function (result) {
            alert("投票成功！");
        },
        error: function () {
            alert('PostVote 错误。');
        }

    });
}